package gateway.server.lifecycle;

import gateway.api.aware.ExecutorServiceAware;
import gateway.api.engine.Engine;

/**
 * @author Jin Zheng
 * @since 1.0 2020-09-27
 */
public class ExecutorServiceLifecycle implements Lifecycle
{
	private final Engine engine;

	public ExecutorServiceLifecycle(Engine engine)
	{
		this.engine = engine;
	}

	@Override
	public boolean accepted(Object target)
	{
		return target instanceof ExecutorServiceAware;
	}

	@Override
	public void handle(Object target) throws Exception
	{
		ExecutorServiceAware aware = (ExecutorServiceAware) target;
		aware.setExecutorService(engine.getExecutorService());
	}
}
